﻿@using Grand.Business.Core.Interfaces.Checkout.Orders
@using Grand.Business.Core.Interfaces.Common.Localization
@using Grand.Domain.Payments
@using Grand.Domain.Shipping
@using Grand.Web.Admin.Components
@using Grand.Web.Common.TagHelpers.Admin
@using Microsoft.AspNetCore.Mvc.TagHelpers
@model AffiliateModel

@inject IOrderStatusService orderStatusService;
@inject ITranslationService translationService;

<div asp-validation-summary="All"></div>
<input asp-for="Id" type="hidden"/>
<admin-tabstrip name="affiliate-edit" BindGrid="true">
    <items>
        <tabstrip-item text="@Loc["Admin.Affiliates.Info"]" tab-index="0">
            <content>
                <div>
                    <partial name="Partials/CreateOrUpdate.TabInfo" model="Model"/>
                </div>
            </content>
        </tabstrip-item>
        @if (!string.IsNullOrEmpty(Model.Id))
        {
            var model = new AffiliatedOrderListModel
            {
                AffliateId = Model.Id
            };
            var status = await orderStatusService.GetAll();

            //order statuses
            model.AvailableOrderStatuses = status.Select(x => new SelectListItem { Value = x.StatusId.ToString(), Text = x.Name }).ToList();
            model.AvailableOrderStatuses.Insert(0, new SelectListItem { Text = translationService.GetResource("Admin.Common.All"), Value = "" });

            //payment statuses
            model.AvailablePaymentStatuses = EnumTranslationService.ToSelectList(PaymentStatus.Pending, false).ToList();
            model.AvailablePaymentStatuses.Insert(0, new SelectListItem { Text = translationService.GetResource("Admin.Common.All"), Value = "" });

            //shipping statuses
            model.AvailableShippingStatuses = EnumTranslationService.ToSelectList(ShippingStatus.Pending, false).ToList();
            model.AvailableShippingStatuses.Insert(0, new SelectListItem { Text = translationService.GetResource("Admin.Common.All"), Value = "" });

            <tabstrip-item text="@Loc["Admin.Affiliates.Customers"]" tab-index="1">
                <content>
                    <div>
                        <partial name="Partials/CreateOrUpdate.TabCustomers" model="Model"/>
                    </div>
                </content>
            </tabstrip-item>
            <tabstrip-item text="@Loc["Admin.Affiliates.Orders"]" tab-index="2">
                <content>
                    <div>
                        <partial name="Partials/CreateOrUpdate.TabOrders" model="model"/>
                    </div>
                </content>
            </tabstrip-item>
        }
        <vc:admin-widget widget-zone="affiliate_details_tabs" additional-data="Model"/>
    </items>
</admin-tabstrip>